﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;


namespace Model.WaiGaoQiao
{
    /// <summary>
    /// 菜单信息
    /// </summary>
    public class MenuInfo
    {
        public int Sid
        {
            get;
            set;
        }
        public string ModularId
        {
            get;
            set;
        }
        public string Url
        {
            get;
            set;
        }
        public string Title
        {
            get;
            set;
        }
        public string Description
        {
            get;
            set;
        }
        public string UserList
        {
            get;
            set;
        }
        public int NodeId
        {
            get;
            set;
        }
        public int PnodeId
        {
            get;
            set;
        }
        public string ImageUrl
        {
            get;
            set;
        }
        /// <summary>
        /// 根据条件获取菜单
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public List<MenuInfo> GetMenuBy(string condition)
        {
            DataAccessMenu dam = new DataAccessMenu();
            DataSet ds = dam.GetMenuBy(condition);
            List<MenuInfo> menulist = new List<MenuInfo>();
            MenuInfo menu = null;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                menu = new MenuInfo();
                menu.Sid = Convert.ToInt32(dr[0]);
                menu.ModularId = dr[1].ToString();
                menu.Url = dr[2].ToString();
                menu.Title = dr[3].ToString();
                menu.Description = dr[4].ToString();
                menu.UserList = dr[5].ToString();
                menu.NodeId = Convert.ToInt32(dr[6]);
                menu.PnodeId = Convert.ToInt32(dr[7]);
                menu.ImageUrl = dr[8].ToString();
                menulist.Add(menu);
            }
            return menulist;
        }

        public int BindMenuToRole(string roleid, int meid)
        {
            DataAccessMenu dam = new DataAccessMenu();
            return dam.BindMenuToRole(roleid, meid);
        }

        public int NotBindMenuToRole(string roleid, int meid)
        {
            DataAccessMenu dam = new DataAccessMenu();
            return dam.NotBindMenuToRole(roleid, meid);
        }
        /// <summary>
        /// 清楚菜单绑定
        /// </summary>
        /// <returns></returns>
        public int ClearBindMenuToRole(string roleid)
        {
            DataAccessMenu dam = new DataAccessMenu();
            return dam.ClearBindMenuToRole(roleid);
        }
        /// <summary>
        /// 获取已经绑定的菜单
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public IList<MenuInfo> GetBindedMenu(string roleid)
        {
            DataAccessMenu dam = new DataAccessMenu();
            string condition = "where NodeID IN (select MenuId from Tbt_RoleAndMenu where RoleId = '" + roleid + "')";
            DataSet ds = dam.GetMenuBy(condition);
            List<MenuInfo> menulist = new List<MenuInfo>();
            MenuInfo menu = null;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                menu = new MenuInfo();
                menu.Sid = Convert.ToInt32(dr[0]);
                menu.ModularId = dr[1].ToString();
                menu.Url = dr[2].ToString();
                menu.Title = dr[3].ToString();
                menu.Description = dr[4].ToString();
                menu.UserList = dr[5].ToString();
                menu.NodeId = Convert.ToInt32(dr[6]);
                menu.PnodeId = Convert.ToInt32(dr[7]);
                menu.ImageUrl = dr[8].ToString();
                menulist.Add(menu);
            }
            return menulist;
        }
    }

}
